<?php

namespace App\Imports;


use App\Models\AgentModel;
use App\Models\DictionaryModel;
use App\Models\dispatch\DriverModel;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use stdClass;
use App\Models\DeptModel;
use App\Models\AdminRoleModel;

class RouteImport implements ToCollection, WithMultipleSheets
{


    private $result;

    public function __construct() {
        $this->result = new stdClass;
    }

    public function collection(Collection $rows){
        $lines = [];
        $this->result->error = [];

        $data = [];
        foreach ($rows as $k => $row){
            if($k == 0) continue;
            $one = [];
            foreach ($row as $k2 => $v){
                $one[$rows[0][$k2]] = $v;
                if($rows[0][$k2] == 'noCache'){
                    $one[$rows[0][$k2]] = $v ? 1 : 0;
                }
            }
            $data[] = $one;
        }


        $this->result->lines = $data;
    }

    public function sheets(): array {
        return [ 0 => $this];
    }

    public function get_result(){
        return $this->result;
    }


}
